package org.logistics;



import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.map.MKEvent;

import android.app.Application;
import android.content.Context;
import android.widget.Toast;
/**
 * 
 * @author yimou
 *初始化APP
 */
public class KeyManager  extends Application{

	 private static KeyManager mInstance = null;
	    public boolean m_bKeyRight = true;
	    BMapManager mBMapManager1 = null;

	    public static final String strKey1 = "B35aaf9987fd06500f9ae1170510ab94";
	    public static final String strKey2 = "C36c5bdc2a10e15215755564406a3421";
		
		@Override
	    public void onCreate() {
		    super.onCreate();
			mInstance = this;
			initEngineManager(this);
		}
		
		public void initEngineManager(Context context) {
	            mBMapManager1 = new BMapManager(context);
	            if (!mBMapManager1.init(strKey1,new MyGeneralListener())) {
		            Toast.makeText(KeyManager.getInstance().getApplicationContext(), 
		                    "BMapManager2  初始化错误!", Toast.LENGTH_LONG).show();
		        }
		}
		
		public static KeyManager getInstance() {
			return mInstance;
		}
		
		
		// 常用事件监听，用来处理通常的网络错误，授权验证错误等
	    static class MyGeneralListener implements MKGeneralListener {
	        
	        @Override
	        public void onGetNetworkState(int iError) {
	            if (iError == MKEvent.ERROR_NETWORK_CONNECT) {
	            	
	            }
	            else if (iError == MKEvent.ERROR_NETWORK_DATA) {
	                Toast.makeText(KeyManager.getInstance().getApplicationContext(), "输入正确的检索条件！",
	                        Toast.LENGTH_LONG).show();
	            }
	            // ...
	        }

	        @Override
	        public void onGetPermissionState(int iError) {
	            if (iError ==  MKEvent.ERROR_PERMISSION_DENIED) {
	                //授权Key错误：
	                Toast.makeText(KeyManager.getInstance().getApplicationContext(), 
	                        "请在 DemoApplication.java文件输入正确的授权Key！", Toast.LENGTH_LONG).show();
	                KeyManager.getInstance().m_bKeyRight = false;
	            }
	        }
	    }
	
	
}
